package emulator.unittest.hardware.nmos6502.timing;


import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

import emulator.EmulatorException;

public class ImpliedTest {

	TimingTestBase test_base = null;
	
	@Before
	public void setUp() throws Exception {
		test_base = new TimingTestBase();
	}
	
	@Test
	public void testBRK() throws EmulatorException
	{
		test_base.resizeMemory(65536);
		assertEquals(7, getCycles(0x00));
	}
	
	@Test
	public void testCLC() throws EmulatorException
	{
		assertEquals(2, getCycles(0x18));
	}

	@Test
	public void testCLD() throws EmulatorException
	{
		assertEquals(2, getCycles(0xD8));
	}

	@Test
	public void testCLI() throws EmulatorException
	{
		assertEquals(2, getCycles(0x58));
	}

	@Test
	public void testCLV() throws EmulatorException
	{
		assertEquals(2, getCycles(0xB8));
	}

	@Test
	public void testDEX() throws EmulatorException
	{
		assertEquals(2, getCycles(0xCA));
	}

	@Test
	public void testDEY() throws EmulatorException
	{
		assertEquals(2, getCycles(0x88));
	}

	@Test
	public void testINX() throws EmulatorException
	{
		assertEquals(2, getCycles(0xE8));
	}

	@Test
	public void testINY() throws EmulatorException
	{
		assertEquals(2, getCycles(0xC8));
	}

	@Test
	public void testNOP() throws EmulatorException
	{
		assertEquals(2, getCycles(0xEA));
	}

	@Test
	public void testPHA() throws EmulatorException
	{
		assertEquals(3, getCycles(0x48));
	}

	@Test
	public void testPHP() throws EmulatorException
	{
		assertEquals(3, getCycles(0x08));
	}

	@Test
	public void testPLA() throws EmulatorException
	{
		assertEquals(4, getCycles(0x68));
	}

	@Test
	public void testPLP() throws EmulatorException
	{
		assertEquals(4, getCycles(0x28));
	}

	@Test
	public void testRTI() throws EmulatorException
	{
		assertEquals(6, getCycles(0x40));
	}

	@Test
	public void testRTS() throws EmulatorException
	{
		assertEquals(6, getCycles(0x60));
	}

	@Test
	public void testSEC() throws EmulatorException
	{
		assertEquals(2, getCycles(0x38));
	}

	@Test
	public void testSED() throws EmulatorException
	{
		assertEquals(2, getCycles(0xF8));
	}

	@Test
	public void testSEI() throws EmulatorException
	{
		assertEquals(2, getCycles(0x78));
	}

	@Test
	public void testTAX() throws EmulatorException
	{
		assertEquals(2, getCycles(0xAA));
	}

	@Test
	public void testTAY() throws EmulatorException
	{
		assertEquals(2, getCycles(0xA8));
	}

	@Test
	public void testTSX() throws EmulatorException
	{
		assertEquals(2, getCycles(0xBA));
	}

	@Test
	public void testTXA() throws EmulatorException
	{
		assertEquals(2, getCycles(0x8A));
	}

	@Test
	public void testTXS() throws EmulatorException
	{
		assertEquals(2, getCycles(0x9A));
	}

	@Test
	public void testTYA() throws EmulatorException
	{
		assertEquals(2, getCycles(0x98));
	}

	private int getCycles(int opcode) throws EmulatorException
	{
		test_base.setCommand(0, opcode, 0, 0);
		test_base.execute();
		return test_base.getElapsedCycles();
	}
}
